package projet.metier;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Map.Entry;

import javax.swing.JOptionPane;

/**
 * Adding methods for help the developer.
 *
 * @author Ambroise
 */
public class Helper {

	/**
	 * Display a HashMap.
	 * 
	 * @param H - HashMap - The HashMap to display.
	 * @param nameHashMap - String - The HashMap's label.
	 */
	@SuppressWarnings("rawtypes")
	public static void displayHashMap(HashMap H, String nameHashMap) {
		// Set est l'interface d'une liste sans doublon
		// Cette liste contient l'ensemble des pairs clef-valeur
		@SuppressWarnings("unchecked")
		Set<Entry<Object, Object>> entrySet = H.entrySet();

		System.out.println("--------------------- --------------------------");
		System.out.println("------------- Contenu de "+nameHashMap+" ---------------");
		System.out.println("--------------------- --------------------------");

		// On crée un itérateur sur la "Set"
		Iterator<Entry<Object, Object>> it = entrySet.iterator();

		String content = "";
		while (it.hasNext()) {
			Entry<Object, Object> entry = it.next();
			
			content+= entry.getKey() + "("+entry.getKey().getClass().getSimpleName()+")" + " = ";
			if(entry.getValue().getClass().isPrimitive()){
				content+= entry.getValue()+ "("+entry.getValue().getClass().getSimpleName()+")\n";
			}else if(entry.getValue().getClass().isArray()){
				content += "Array"+Arrays.deepToString((Object[]) entry.getValue())+"\n";
			}
			
		}
		
		System.out.println(content);
		JOptionPane.showMessageDialog(null, content, "Contenu de la HashMap", JOptionPane.INFORMATION_MESSAGE);
		
	}
}
